package com.stars.Test.controller;

import com.alibaba.fastjson2.JSONObject;
import com.stars.base.entity.Result;
import com.stars.util.jwt.JWTUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2022/11/19 18:42
 * @description : 登录测试
 */
@RestController
@RequestMapping("/test/login")
public class TestLoginController {

    @RequestMapping("/generateToken")
    public Result generateToken(String id) {

        String token = JWTUtil.generateToken(id);

        JSONObject obj = new JSONObject();
        obj.put("token", token);

        return Result.success(obj);
    }

    @RequestMapping("/validToken")
    public Result validToken(String token){
        try {
            return Result.success(JWTUtil.verify(token));
        }catch(Exception e){
            e.printStackTrace();
            return Result.error();
        }
    }
}
